# for i in range(-127,128,2):
#     print(i,end="\t")
    # print(i,sep="***")
#打印1000以内被5整除的数,三个间隔
# for i in range(1,1000,3):
#     if i%5==0:
#         print(i,end="\t")
#猜数字
# import random
# num=random.randint(20,100)
# print(num)
# if num>50:
#     print("猜小一点")
#     guess=int(input("请输入你猜的数字："))
#     while guess!=num:
#         if guess<num:
#             print("猜大一点")
#             guess=int(input("请输入你猜的数字："))
#         else:
#             print("猜小一点")
#             guess=int(input("请输入你猜的数字："))
#     else:
# #         print("猜对了")
# 遍历1到100的整数，查找包含7或能被7整除的数字
# for i in range(1, 100 + 1):
#     # 如果数字i能够被7整除或者包含数字7
#     if i % 7 == 0 or str(i).find("7") != -1:
#         if i % 7 == 0 or str(i).count('7') >0:
#             print(i,end="\t")
# print("\n")

#打印菱形
# b=int(input("请输入一个整数："))
# if b%2==0:
#     a=b-3
# else:
#     a=b-2
# for i in range(1, b+1,2):
#     print(i,end="\t")
#     print(("*" * i).center(b) )
#     #center()方法:将生成的字符串在总宽度为11的情况下居中对齐。如果字符串长度小于11，左右会填充空格。例如，*会变成   *   （两边各有4个空格）。
# for i in range(a, 0, -2):
#     print(i,end="\t")
#     print(("*" * i).center(b) )
# #打印水仙花数 (3位数，每个位上的数字的立方和等于该数本身)


#打印100以内的质数
# for num in range(2, 1000):
#     if num > 1:
#         for i in range(2, num):
#             if (num % i) == 0:
#                 break
#         else:
#             print(num, end="\t")
# 打印斐波那契
# 打印100完数
#     #打印菱形2 用嵌套循环
#打印斐波纳契数列
# a, b = 0, 1
# for _ in range(100):
#     print(a, end="\n")
#     a, b = b, a + b
# def fibonacci(n):
#     # 如果n小于等于0，则返回空列表
#     if n <= 0:
#         return []
#     # 如果n为1，返回只包含第一个元素的列表
#     elif n == 1:
#         return [0]
#     # 如果n为2，返回前两个元素的列表
#     elif n == 2:
#         return [0, 1]
#     # 初始化前两个斐波纳契数
#     fib_sequence = [0, 1]
#     # 计算后续的斐波纳契数
#     for i in range(2, n):
#         next_value = fib_sequence[-1] + fib_sequence[-2]
#         fib_sequence.append(next_value)
#     return fib_sequence
# print(fibonacci(100))
#     #打印九九乘法表
# 打印九九乘法表
# for i in range(1, 10):
#     for j in range(1, i + 1):
#         print(f"{j} * {i} = {i * j}", end="\t")
#     print()
# 打印 100 以内的所有完美数
def is_perfect_number(n):
    if n < 1:
        return False
    factors_sum = sum(i for i in range(1, n) if n % i == 0)
    return factors_sum == n
# 打印 100 以内的完美数
perfect_numbers = [num for num in range(1, 101) if is_perfect_number(num)]
print("100 以内的完美数有：", perfect_numbers)
# def is_perfect_number(n):
#     if n < 1:
#         return False
#
#     factors_sum = 0
#     for i in range(1, n):
#         if n % i == 0:
#             factors_sum += i
#
#     return factors_sum == n
#
# # 检查 100 以内的所有数
# perfect_numbers = []
# for num in range(1, 101):
#     if is_perfect_number(num):
#         perfect_numbers.append(num)
#
# # 打印完美数
# print("100 以内的完美数有：", perfect_numbers)


